package org.cboard.dto;

import java.util.Map;

import javax.annotation.Nullable;

import org.cboard.pojo.BoardCommonBase;
import org.cboard.pojo.DashboardWidget;
import org.cboard.services.role.RolePermission;

import com.alibaba.fastjson.JSONObject;
import com.google.common.base.Function;

/**
 * Created by yfyuan on 2016/8/19.
 */
public class ViewDashboardWidget extends BoardCommonBase{

    private Map<String, Object> data;
    private boolean edit;
    private boolean delete;

    public static final Function TO = new Function<DashboardWidget, ViewDashboardWidget>() {
        @Nullable
        @Override
        public ViewDashboardWidget apply(@Nullable DashboardWidget input) {
            return new ViewDashboardWidget(input);
        }
    };

    public ViewDashboardWidget(DashboardWidget widget) {
        this.id = widget.getId();
        this.userId = widget.getUserId();
        this.name = widget.getName();
        this.categoryName = widget.getCategoryName();
        this.data = JSONObject.parseObject(widget.getData());
        this.edit = RolePermission.isEdit(widget.getPermission());
        this.delete = RolePermission.isDelete(widget.getPermission());
    }

    public boolean isEdit() {
        return edit;
    }

    public void setEdit(boolean edit) {
        this.edit = edit;
    }

    public boolean isDelete() {
        return delete;
    }

    public void setDelete(boolean delete) {
        this.delete = delete;
    }

  
    public Map<String, Object> getData() {
        return data;
    }

    public void setData(Map<String, Object> data) {
        this.data = data;
    }
}
